package com.lagou.mr.sorttest;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class SortBean implements WritableComparable<SortBean> {

    private int index;//排名
    private int num;//原始数据

    //比较方法
    @Override
    public int compareTo(SortBean bean) {
        if (this.num > bean.getNum()) {
            return 1;
        }else if (this.num < bean.getNum()){
            return -1;
        }
        return 0;
    }

    //序列化
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(index);
        out.writeInt(num);
    }

    //反序列化
    @Override
    public void readFields(DataInput in) throws IOException {
        this.index = in.readInt();
        this.num = in.readInt();
    }

    public SortBean() {
    }

    public SortBean(int index, int num) {
        this.index = index;
        this.num = num;
    }

    @Override
    public String toString() {
        return index + "\t" + num ;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }
}
